<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>提交订单成功管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					if(!$('input:radio[name="refrigeratetype"]:checked').val()){
						$(".ref-msg").show();
						return ;
					}
					if($('input:radio[name="refrigeratetype"]:checked').val()=="3"&&!$(".refinput").val()){
						$(".ref-msg").show();
						return ;
					}
					if(!$('input:radio[name="transportation"]:checked').val()){
						$(".tran-msg").show();
						return ;
					}
					if($('input:radio[name="transportation"]:checked').val()=="3"&&!$(".traninput").val()){
						$(".tran-msg").show();
						return ;
					}
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			$("#tab_show").hide();
			$(".tran-msg").hide();
			$(".ref-msg").hide();
			$(".refinput").focus(function(){
				$(".ref-msg").hide();
				
			});
			$(".refinput").blur(function(){
				if(!$(".refinput").val()){
					$(".ref-msg").show();
				}
				
			});
			$(".traninput").focus(function(){
				$(".tran-msg").hide();
			});
			$(".traninput").blur(function(){
				if(!$(".traninput").val()){
					$(".tran-msg").show();
				}
			});
			
			$(".trantype").click(function(){
				$(".tran-msg").hide();
				var str=$(this).val();
				if(str=='3'){
					$(".traninput")[0].readOnly=false;
				}else{
					$(".traninput").val("");
					$(".traninput")[0].readOnly=true;
				}
			})
			$(".reftype").click(function(){
				$(".ref-msg").hide();
				var str=$(this).val();
				if(str=='3'){
					$(".refinput")[0].readOnly=false;
				}else{
					$(".refinput").val("");
					$(".refinput")[0].readOnly=true;
				}
			})
			
			$("#add").click(function(){
				addRow();
				$(".select_sort").hide();
			});
			
			
		});
		var sorts="";
		function sort(obj){
			sorts=$(obj).find("span").text();
			$(obj).find("span").text("");
			$(obj).find("select").css("display","inline");
			$(obj).attr("onclick","");
			$(obj).find("select").focus();
		}
		function getSort(){
			
		}
		
		function changeSort(obj){
			if($(obj).val()=="1"){
				$(obj).parent().attr("onclick","sort(this)");
				$(obj).parent().html('<span>一类</span><select  class="select_sort required" onchange="changeSort(this)" onblur="changeSort(this)"><option value ="0">请选择</option><option value ="1">一类</option><option value ="2">二类</option></select><span style="color:red"></span>');
				$(".select_sort").hide();
			}
			if($(obj).val()=="2"){
				$($(obj).parent()).attr("onclick","sort(this)");
				$(obj).parent().html('<span>二类</span><select  class="select_sort required" onchange="changeSort(this)" onblur="changeSort(this)"><option value ="0">请选择</option><option value ="1">一类</option><option value ="2">二类</option></select><span style="color:red"></span>');
				$(".select_sort").hide();
			}
			$($(obj).parent()).attr("onclick","sort(this)");
			$(obj).parent().html('<span></span><select  class="select_sort required" onchange="changeSort(this)" onblur="changeSort(this)"><option value ="0">请选择</option><option value ="1">一类</option><option value ="2">二类</option></select><span style="color:red"></span>');
			$(".select_sort").hide();
		}
		
		function addRow(){
	        var tab =document.getElementById("tab");
	        var rowIndex = tab.rows.length;
	      //添加一行;
	        var tr  = tab.insertRow();
	        var td1 = tr.insertCell();
	        var td2 = tr.insertCell();
	        var td3 = tr.insertCell();
	        var td4 = tr.insertCell();
	        var td5 = tr.insertCell();
	        var td6 = tr.insertCell();
	        var td7 = tr.insertCell();
	        
	        td1.innerHTML = ""+rowIndex;
	        td2.innerHTML = "<a href='#' onclick='deleteRow(this)'>删除</a>";
	        td3.innerHTML = '';
	        td4.innerHTML = '';
	        td5.innerHTML = '';
	        td6.innerHTML = '';
	        $(td7).attr("onclick","sort(this)");
// 	        $(td7).addClass("select");
	        td7.innerHTML = '<select  class="select_sort required" onchange="changeSort(this)" onblur="changeSort(this)"><option value ="0">请选择</option><option value ="1">一类</option><option value ="2">二类</option></select><span style="color:red"></span>';
}
		
		function deleteRow(obj){
		    var tab = document.getElementById("tab");
		    //获取tr对象;
		    var tr = obj.parentNode.parentNode;
		    if(tab.rows.length>1){
		        tr.parentNode.removeChild(tr);
		    }
		    //重新生成行号;
		    initRows();
		}

		function initRows(tab){//重新编号
			var tab=document.getElementById("tab");
		     var tabRows = tab.rows.length;
		     for(var i = 1;i<tabRows;i++){
		    	 tab.rows[i].cells[0].innerHTML=""+i;
		    }
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
<%-- 		<li><a href="${ctx}/electronic_supervise/bsElectronicSupervise/">提交订单成功列表</a></li> --%>
		<li class="active"><a href="${ctx}/electronic_supervise/bsElectronicSupervise/form?id=${bsElectronicSupervise.id}">提交订单成功<shiro:hasPermission name="electronic_supervise:bsElectronicSupervise:edit">${not empty bsElectronicSupervise.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="electronic_supervise:bsElectronicSupervise:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="bsElectronicSupervise" action="${ctx}/electronic_supervise/bsElectronicSupervise/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="breadcrumb">
			<table class="table table-bordered">
				
				<tr>
					<th>日期：</th>
					<td>
						<input name="createDate" type="text" readonly="readonly"  class=" Wdate required"
							value="<fmt:formatDate value="${bsElectronicSupervise.createDate}" pattern="yyyy-MM-dd"/>"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
						<span class="help-inline"><font color="red">*</font> </span>
					</td>
					<th>单号</th>
					<td><form:input path="no" readonly="true" htmlEscape="false" maxlength="20" class="input-xlarge"/>
						<span class="help-inline">单号系统自动生成</span></td>
				</tr>
				<tr>
					<th>类型</th>
					<td colspan="3"><form:input path="type" readonly="true" value="领取/购进" htmlEscape="false" maxlength="20" class="input-xlarge span2 minWidth" /></td>
				</tr>
				
				<tr>
					<th>供货单位:</th>
					<td>
						<form:input path="supplyorgName" htmlEscape="false" maxlength="255" class="input-xlarge required span2 minWidth"/>
						<span class="help-inline"><font color="red">*</font> </span>
					</td>
					<th>供货单位经手人</th>
					<td><form:input path="consignorName" htmlEscape="false" maxlength="50" class="input-xlarge span2 minWidth required"/>
						<span class="help-inline"><font color="red">*</font> </span></td>
				</tr>
				<tr>
					<th>收货单位</th>
					<td><form:input path="receiveorgName" htmlEscape="false" maxlength="255" class="input-xlarge span2 minWidth"/></td>
					<th>收货单位经手人</th>
					<td><form:input path="consigneeName" htmlEscape="false" maxlength="50" class="input-xlarge span2 minWidth"/></td>
				</tr>
				
				
				<tr>
				<td colspan="4">
					<table  class="table table-bordered" id="tab">
						<caption>扫描监管码</caption>
						<thead>
						<tr>
					 		<th>编号</th>
					 		<th>操作</th>
					 		<th>当前物品电子监管码</th>
					 		<th>上级包装电子监管码</th>
					 		<th>包装级别</th>
					 		<th>数量(支或粒)</th>
					 		<th><span class="help-inline"><font color="red">*</font></span>疫苗属性</th>
					 	</tr>
					 	</thead>
					 <tbody class="table_content">
						 		
					</tbody>
					</table>
					<input class="btn btn-primary" id="add" name="btn" type="button" value="新增"/>
				</td>
				</tr>
				
				<tr>
					<th>疫苗运输工具</th>
					<td colspan="3">
						<form:radiobuttons path="transportation" name="transportation"  items="${fns:getDictList('bs_order_transportation')}"   itemLabel="label" itemValue="value" class="required trantype"/>
						<form:input path="otherTransportation"   readonly="true" htmlEscape="false" maxlength="50" class="traninput"/>
						<label for="transportation" class="error tran-msg">必填信息</label>
						<span class="help-inline"><font color="red">*</font> </span>
					</td>
				</tr>
 
				
				<tr>
					<th>疫苗冷藏方式</th>
					<td colspan="3">
						<form:radiobuttons path="refrigeratetype" name="refrigeratetype"  items="${fns:getDictList('bs_order_refrigeratetype')}" itemLabel="label" itemValue="value" class="required reftype"/>
						<form:input path="otherRefrigeratetype"   readonly="true" htmlEscape="false" maxlength="50" class="refinput"/>
						<label for="transportation" class="error ref-msg">必填信息</label>
						<span class="help-inline"><font color="red">*</font></span>
					</td>
				</tr>
				<tr>
				<br/>
				<th>备注</th>
				<td colspan="3">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="100" class="input-xxlarge" />
				 <label><font color="red">最多输入100个字</font></label>
				</td>
				</tr>
			</table>
		</div>
		
		</div>		
 
		<div class="form-actions" >
<%-- 			<shiro:hasPermission name="electronic_supervise:bsElectronicSupervise:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="提交订单"/>&nbsp;</shiro:hasPermission> --%>
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="提交订单"/>
<!-- 			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/> -->
		</div>
	</form:form>
</body>
</html>